package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ReservationDto;
import com.zzyl.entity.TimeCount;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "客户预约管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/customer/reservation")
public class CustomerReservationController {

    private final ReservationService reservationService;

    @GetMapping(path = "/cancelled-count")
    @ApiOperation("获取已取消的预约数量")
    public ResponseResult<Integer> getCancelledCount() {
        return ResponseResult.success(reservationService.getCancelledCount());
    }

    @GetMapping(path = "/countByTime")
    @ApiOperation("根据时间段统计预约数量")
    public ResponseResult<List<TimeCount>> countByTime(long time) {
        return ResponseResult.success(reservationService.countByTime(time));
    }

    @PostMapping
    @ApiOperation("新增预约")
    public ResponseResult<Void> addReservation(@RequestBody ReservationDto reservationDto) {
        reservationService.addReservation(reservationDto);
        return ResponseResult.success();
    }

    @GetMapping(path = "/page")
    @ApiOperation("分页查询预约")
    public ResponseResult<PageResponse<ReservationVo>> findReservationPage(int pageNum,int pageSize,String status) {
        return ResponseResult.success(reservationService.findReservationPage(pageNum, pageSize, status));
    }

    @PutMapping(path = "/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult<Void> cancelReservation(@PathVariable Long id) {
        reservationService.cancelReservation(id);
        return ResponseResult.success();
    }
}
